package com.zzw.mvvm.pages.demo;

import android.util.Log;
import android.view.View;

import com.zzw.mvvm.R;
import com.zzw.mvvm.base.BaseActivity;
import com.zzw.mvvm.base.BaseViewModel;
import com.zzw.statelayoutlib.StatefulLayout;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

import butterknife.BindView;

public class StatusDemoActivity extends BaseActivity<BaseViewModel> {


    @BindView(R.id.statefull_layout)
    StatefulLayout statefullLayout;

    @Override
    public int getLayoutId() {
        return R.layout.activity_status_demo;
    }

    public void click(View v) {
        switch (v.getId()) {
            case R.id.bt1:
                viewModel.setCurrentStatus(1,"");
                break;
            case R.id.bt2:
                viewModel.setCurrentStatus(2, "");
                break;
            case R.id.bt3:
                viewModel.setCurrentStatus(3, "");
                break;
            case R.id.bt4:
                viewModel.setCurrentStatus(4, "");
                break;
        }
    }

    @Override
    public void bindViewModel() {
        viewModel.getCurrentStatus().observe(this, statusPJ -> {
            switch (statusPJ.getCode()) {
                case 1:
                    statefullLayout.showContent();
                    break;
                case 2:
                    statefullLayout.showEmpty();
                    break;
                case 3:
                    statefullLayout.showError("err", v -> {

                    });
                    break;
                case 4:
                    statefullLayout.showLoading();
                    break;

            }
        });
    }
}
